Unit BFormLUnitMain;

{$mode objfpc}{$H+}

Interface

Uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
  ExtCtrls, Buttons, StdCtrls, Menus, ActnList, math, LazUnitIntf, base64,
  fphttpserver, fpmimetypes, HTTPDefs, fgl, strutils;

Type

  { TLUnitMain }

  TLUnitMain = Class(TForm)
    ActionList1: TActionList;
    ImageList1: TImageList;
    ImageTests: TImage;
    MemoTests: TMemo;
    MenuItem1: TMenuItem;
    PanelToolBar: TPanel;
    PopupMenuActions: TPopupMenu;
    Procedure FormCreate(Sender: TObject);
    Procedure FormResize(Sender: TObject);
  Private
    { private declarations }
    bResultColor: Integer;
    Procedure RepaintTestImage;
  Public
    { public declarations }

    Procedure Highlight(Const aSuccess: Boolean);
    Procedure SetResultColor(Const aColor: Integer);
  End;

Var
  LUnitMain: TLUnitMain = nil;

Implementation

{ TLUnitMain }

Procedure TLUnitMain.RepaintTestImage;
Var
  aRect: TRect;
Begin
  aRect.Top := 2;
  aRect.Left := 2;
  aRect.Bottom := Max(2, ImageTests.Picture.Bitmap.Height - 6);
  aRect.Right := Max(2, ImageTests.Picture.Bitmap.Width - 6);

  With ImageTests.Canvas Do
    Begin
      Brush.Color := clBtnFace;
      FillRect(ClipRect);
      Brush.Color := bResultColor;
      RoundRect(ImageTests.Canvas.ClipRect, 20, 20);
    End;
End;

Procedure TLUnitMain.Highlight(Const aSuccess: Boolean);
Begin
  If aSuccess Then SetResultColor(clGreen)
  Else SetResultColor(clRed);
End;

Procedure TLUnitMain.SetResultColor(Const aColor: Integer);
Begin
  bResultColor := aColor;
  RepaintTestImage;
End;

Procedure TLUnitMain.FormResize(Sender: TObject);
Begin
  If Height < 100 Then
    Begin
      PanelToolBar.Align := alClient;
      MemoTests.Hide;
    End
  Else
    Begin
      PanelToolBar.Height := 36;
      ImageTests.Height := 32;
      PanelToolBar.Align := alTop;
      MemoTests.Show;
    End;

  ImageTests.Picture.Bitmap.SetSize(Max(0, Width - 4), ImageTests.Height - 4);
  RepaintTestImage;
end;

Procedure TLUnitMain.FormCreate(Sender: TObject);
Begin
  bResultColor := clBtnFace;
  ImageTests.Canvas.Pen.Color := clBtnFace;
end;

{$R *.lfm}

End.

